This text file contains code and general logic for defining neighboring parcels and assigning census blocks IDs to parcels.


********************************************************

STEP 1: prep assessor data for GIS

********************************************************
^^^ begin DO file
/*
This *.do file creates xy files for use in GIS.
Specifically, I create the following files:

1. AO_XY.csv: for mapping census blocks to parcels
- no enrollment information is used
- output is simple: parcel, zip, pt_x, pt_y

2. unmatched_aoxygis.csv: for later analysis if desired
- unmatched parcels between the June xy assessor data the the parcel 
  shape file recieved from Clark County GIS dept.

3. unmatched_enrollaoxy.csv: for later analysis if desired
- enrollments that do not match any xy assessor data
- these parcels appear no longer to exist

4. enrollment_aoxy.csv: for GIS analysis of enrollment locations
- uses original enrollment data
- all types (SF, MF, CI, GC) are included
- those undertaking >1 conversion are included
*/

clear
set more off

* ------------------------------------------------------------------------------
* set paths
global root "[include paths here]"
global ..   "[include other subdirectories]"

* -----------------------------------------------------
* 1a. Make csv file for mapping census blocks to parcels
* -----------------------------------------------------

*_______________________
* Import AO_XY text file (raw data from county assessor)
import delim using "$inputao/aoparcelxyzip.txt", delim("|") stringc(_all) clear

rename v1 parcel
rename v2 zip
rename v3 pt_x
rename v4 pt_y

*________________________
* Clean AO_XY text file
duplicates report
duplicates tag, gen(dup_all)
duplicates report parcel pt_x pt_y
duplicates tag parcel pt_x pt_y, gen(dup_pxy)

duplicates drop parcel pt_x pt_y, force
duplicates report parcel
drop dup_*

destring pt_x pt_y, replace
sort parcel

la da "cleaned AO_XY data: parcel, zip, pt_x pt_y"
save "$intermediate/AO_XY.dta", replace
export delimited parcel zip pt_x pt_y using "$output/AO_XY.csv", q replace
export delimited parcel zip pt_x pt_y using "$outGIS/AO_XY.csv", q replace

* -----------------------------------------------------
* 1b. Compare with parcels from GIS dept
* -----------------------------------------------------
import delim using "$root\GIS\parcel_x_TBL.txt", delim(",") stringc(_all) clear
/* 
I created this file by exporting the attribute table from the Parcels_x.shp
(raw shape file data from county assessor)
- created from attribute table of parcel_x.shp (ArcMap: export table option) 
*/

duplicates report
keep apn tax_dist point_x point_y
rename apn parcel
duplicates report parcel point_x point_y // no duplicates

sort parcel
merge 1:1 parcel using "$intermediate/AO_XY.dta"
sort parcel

rename pt_x x_aoxy
rename pt_y y_aoxy
rename point_x x_gis
rename point_y y_gis

destring x_gis y_gis, replace
keep if _merge!=3

replace x_gis = x_aoxy if x_gis==. & _merge == 2
replace y_gis = y_aoxy if y_gis==. & _merge == 2

export delimited using "$output/unmatched_aoxygis.csv", q replace


* ------------------------------------------------
* 2. Make CSV file for GIS map/movie of enrollment
* ------------------------------------------------

*_____________________________________________
* Import and clean the raw SNWA enrollement data
use "$input/1tblWSLEnroll.dta", clear
describe
rename _all, lower

duplicates report parcel enroll_date tot_rebated // no duplicates
duplicates report parcel enroll_date // no duplicates
sort parcel enroll_date

duplicates tag parcel, gen(multi)
by parcel: gen conversion = _n

*_____________________________________________
* merge with AO_XY data
sort parcel enroll_date
merge m:1 parcel using "$intermediate/AO_XY.dta"

// - - - - - - - - - - - - - - - - - - - - - - - - -
preserve 
* create a file of enrollments that do not match with assessor xy data
duplicates drop parcel, force

sort parcel
local vars "parcel enroll_date program conv_sqft tot_rebated wg multi conversion _merge"
export delimited `vars' using "$output/unmatched_enrollaoxy.csv" if _merge==1, quote replace

/* a quick spot check of the ao website of enrolling parcels not in aoxy 
suggests these parcels no longer exist; perhaps partitioned? */
restore
// - - - - - - - - - - - - - - - - - - - - - - - - -

* prep for exporting to csv
keep if _merge==3
drop _merge

sort parcel enroll_date
export delimited using "$output/enrollment_aoxy.csv", quote replace
export delimited using "$outGIS/enrollment_aoxy.csv", quote replace

* remove intermediate files
rm "$intermediate/AO_XY.dta"
^^^ end DO file

********************************************************

STEP 2: match parcel to census blocks

********************************************************

Steps to map parcels to census blocks
1. create AO_XY feature class
- add xy data (file menu) from GIS/input/AO_XY.csv
    projection: NAD_1983_StatePlane_Nevada_East_FIPS_2701_Feet
- data/export data to AO_XY feature class (saved in intermediate.gdb)

2. run parcel_to_censusBlocks model
- I modified this model to use the AO_XY feature class I created in 1.

See also:
- parcel_to_censusBlocks.py
- parcel_to_censusBlocks.png

********************************************************

STEP 3: match parcel to census blocks

********************************************************
Steps in the adjacency analysis

This contains the documentation pertaining to my method for creating a table of parcels that are adjacent to parcels that enrolled.

I use this for the spillover analysis.

________________________________________________________
Process:

1. make enrollment feature class (for use in adjacency and movies)
- add xy data from enrollment_aoxy.csv (created by step 1)
    projection: NAD_1983_StatePlane_Nevada_East_FIPS_2701_Feet
- data/export data to enrollment feature class
- enrollment uses 1tblWSLEnroll.dta (enrollment data from SNWA)
- also created an enrollment_SF feature class

2. load in 'parcels.shp' (parcel shape file from county assessor)
- created parcels_class705
- (enrollment_SF already in from 1.)
- spot checked a few of these, and it appears I should drop 705
- class 705 appear to be large parcels upon which smaller townhomes? are built (these smaller ones have their own parcel numbers. After performing 5. below, I manually checked matched class #705 and found that all these matches were big parcels that had a smaller SF converter contained within them. So I re-created Parcels_noRoads without 705 to save the trouble of dealing with it in Stata.

3. select features: "Label_Clas" = 701 OR "Label_Clas" = 702 OR "Label_Clas" = 703 OR "Label_Clas" = 704 OR "Label_Clas" = 707 OR "Label_Clas" = 801 OR "Label_Clas" = 803 OR "Label_Clas" = 805 OR "Label_Clas" = 807 OR "Label_Clas" = 808 OR "Label_Clas" = 811 OR "Label_Clas" = 812 OR "Label_Clas" = 813

- the remaining features (713-728) I believe are roads, drainage, train tracks, sidewalks, greenways...
- saved selected features to ..intermediate.gdb/parcels_noRoad
  a. export data
  b. save selected features to intermediate.gdb/parcels_noRoad

4. spatial join: analysis/overlay/spatial join
target features: parcels_noRoad
join features: enrollment_SF
output feature class: ...Analysis/GIS/intermediate.gdb/sj1_parcelsEnroll
join operation: one to many (considers that some parcels convert more than once)
unselect "keep all target features"
field map of join features: default
match option: completely contains

NOTE: if apn != parcel, this is a case where multiple parcels are in the same building, but the conversion was assigned to only one of the parcels.

5. (adjacency analysis) spatial join
target features: parcels_noRoad
join features: sj1_parcelsEnroll
output feature class: ...Analysis/GIS/intermediate.gdb/sj2_adjacency 
join operation: one to many (considers that some parcels convert more than once)
unselect "keep all target features"
field map of join features: default
match option: boundary_touches

created and exported an image of adjacency (Figure 7)

6. export attribute table from sj2_adjacency ../Analysis/GIS/output/sj2_adjacency.txt
- apn_1 = parcel
- if apn_1 != parcel, then probably this is a case of a town home with one building being assigned to multiple parcel ids (here, apn = apn_1)